home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / FGDEMO40.ZIP / SOURCE.COM / DISPLAY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-12  |  10.4 KB  |  385 lines

  1. /**********************************************************************\
  2. *                                                                      *
  3. *  display.c -- graphics display functions, bitmaps, scrolling, etc.   *
  4. *                                                                      *
  5. \**********************************************************************/
  6.  
  7. #include "defs.h"
  8. #include "birds.h"
  9. #include "tntmaps.h"
  10.  
  11. /**********************************************************************\
  12. *                                                                      *
  13. *  do_bitmaps -- display some bitmaps on the screen                    *
  14. *                                                                      *
  15. *  the drawmap bitmaps are bigger than the drwimage bitmaps but you    *
  16. *  can have any transparent and visual colors you want                 *
  17. *                                                                      *
  18. \**********************************************************************/
  19.  
  20. do_bitmaps()
  21. {
  22.    /* width, height, position and colors of TNT plunger bitmap */
  23.  
  24.    static int tnt_width[]   = { 6,  3,  4,  4};
  25.    static int tnt_height[]  = {28, 25, 27, 17};
  26.    static int tnt_color[]   = { 0,  7,  8, 15};
  27.    static int tnt_xoffset[] = { 0, 24, 16, 16};
  28.    static int tnt_yoffset[] = { 0, -2, -1, -2};
  29.    static char *tnt_bitmap[4] = {tnt0,tnt7,tnt8,tnt15};
  30.  
  31.    /* width, height, position and colors of "kablooy" explosion */
  32.  
  33.    static int kablooy_width[]   = {13,  6};
  34.    static int kablooy_height[]  = {53,  8};
  35.    static int kablooy_color[]   = { 4, 15};
  36.    static int kablooy_xoffset[] = { 0, 29};
  37.    static int kablooy_yoffset[] = { 0,-24};
  38.    static char *kablooy_bitmap[2] = {kablooy4,kablooy15};
  39.  
  40.    /* strings for info window */
  41.  
  42.    static char *string[] = {
  43.    "Bitmaps",
  44.    "Bitmaps can be clipped, flipped, mode-independent",
  45.    "and mode-specific.",
  46.    };
  47.  
  48.    register int i;
  49.    int x,y;
  50.    int ymin,ymax;
  51.  
  52.    /* clear lower part of screen */
  53.  
  54.    fg_mousevis(OFF);
  55.    fg_restore(0,xlimit,menu_bottom,ylimit);
  56.  
  57.    /* display the info window */
  58.  
  59.    info_window(120,520,60,string,3);
  60.  
  61.    /* calculate where the TNT bitmap is going to go */
  62.  
  63.    ymin = 60;
  64.    ymax = ymin + 4 * (PTSIZE+1);
  65.  
  66.    x = 520;
  67.    y = ymax;
  68.  
  69.    /* put the TNT bitmap next to the info window */
  70.  
  71.    fg_mousevis(OFF);
  72.    for (i = 0; i < 4; i++)
  73.    {
  74.       fg_move(x+tnt_xoffset[i],y+tnt_yoffset[i]);
  75.       fg_setcolor(tnt_color[i]);
  76.       fg_drawmap(tnt_bitmap[i],tnt_width[i],tnt_height[i]);
  77.    }
  78.  
  79.    /* save info window to hidden page, to be replaced after the explosion */
  80.  
  81.    x = 440;
  82.    y = ymax + 20;
  83.    fg_save(400,520,ymin,y);
  84.  
  85.    /* take a rectangular bite out of the info window on the hidden page */
  86.  
  87.    fg_transfer(464,568,144,180,464,y-10,hidden,hidden);
  88.  
  89.    /* pause 1 second */
  90.  
  91.    fg_mousevis(ON);
  92.    fg_waitfor(18);
  93.  
  94.    /* move the plunger down */
  95.  
  96.    fg_mousevis(OFF);
  97.    fg_transfer(544,567,ymax-30,ymax-25,0,5,visual,hidden);
  98.    fg_transfer(0,23,0,5,544,ymax-23,hidden,visual);
  99.    fg_mousevis(ON);
  100.    fg_waitfor(6);
  101.  
  102.    fg_mousevis(OFF);
  103.    fg_transfer(0,23,0,5,544,ymax-21,hidden,visual);
  104.    fg_mousevis(ON);
  105.    fg_waitfor(6);
  106.    fg_mousevis(OFF);
  107.  
  108.    /* display the explosion */
  109.  
  110.    for (i = 0; i < 2; i++)
  111.    {
  112.       fg_move(x+kablooy_xoffset[i],y+kablooy_yoffset[i]);
  113.       fg_setcolor(kablooy_color[i]);
  114.       fg_drawmap(kablooy_bitmap[i],kablooy_width[i],kablooy_height[i]);
  115.    }
  116.  
  117.    /* blink the "kablooy" text 4 times */
  118.  
  119.    for (i = 0; i < 4; i++)
  120.    {
  121.       fg_waitfor(3);
  122.       fg_move(x+kablooy_xoffset[1],y+kablooy_yoffset[1]);
  123.       fg_setcolor(4);
  124.       fg_drawmap(kablooy_bitmap[1],kablooy_width[1],kablooy_height[1]);
  125.       fg_waitfor(3);
  126.       fg_move(x+kablooy_xoffset[1],y+kablooy_yoffset[1]);
  127.       fg_setcolor(15);
  128.       fg_drawmap(kablooy_bitmap[1],kablooy_width[1],kablooy_height[1]);
  129.    }
  130.  
  131.    /* wait a bit, then restore the info window with the corner missing */
  132.  
  133.    fg_waitfor(3);
  134.    fg_restore(440,568,y-68,y);
  135.  
  136.    /* draw the torn edges of the info window using the tear bitmap */
  137.  
  138.    fg_setcolor(0);
  139.    fg_move(461,ymax);
  140.    fg_drawmap(tear,8,29);
  141.  
  142.    /* restore all the stuff on the hidden page */
  143.  
  144.    draw_screen(3);
  145.  
  146.    /* wait for a keystroke, restore the visual page, and return */
  147.  
  148.    fg_mousevis(ON);
  149.    wait_for_keystroke();
  150.  
  151.    fg_mousevis(OFF);
  152.    fg_restore(0,xlimit,menu_bottom,ylimit);
  153.  
  154.    fg_mousevis(ON);
  155.    redraw = TRUE;
  156.  
  157.    return(OK);
  158. }
  159.  
  160. /**********************************************************************\
  161. *                                                                      *
  162. *  do_scaling -- illustrate bitmap scaling                             *
  163. *                                                                      *
  164. *  The bird bitmap is stored as a 20x20 16-color mode-specific bitmap, *
  165. *  which means its size in pixels is 40x20.                             *
  166. *                                                                      *
  167. \**********************************************************************/
  168.  
  169. char bird_unpacked[800];   /* unpacked bird bitmap (40x20) */
  170. char bird_scaled[3200];    /* scaled bird bitmap (80x40 max) */
  171. char bird_packed[1600];    /* packed and scaled bird bitmap (40x40 max) */
  172.  
  173. do_scaling()
  174. {
  175.    register int width, height;
  176.    int x;
  177.    char string[6];
  178.  
  179.    /* convert the 20x20 mode specific bitmap to a 40x20 unpacked bitmap */
  180.  
  181.    fg_unpack(bird1,bird_unpacked,20*20);
  182.  
  183.    /* the bird bitmap uses colors 5 and 15, change color 5 to black */
  184.  
  185.    fg_palette(5,0);
  186.  
  187.    /* display the original 40x20 bird bitmap */
  188.  
  189.    x = 60;
  190.    fg_move(x,250);
  191.    fg_mousevis(OFF);
  192.    fg_drwimage(bird1,20,20);
  193.    fg_setcolor(12);
  194.    center_pstring("40x20",x,x+40,270);
  195.  
  196.    /* scale and display the 40x20 bird bitmap in increasingly larger sizes */
  197.  
  198.    for (width = 50; width <= 80; width+=10)
  199.    {
  200.       x += 100;
  201.       fg_move(x,250);
  202.       height = width / 2;
  203.       fg_scale(bird_unpacked,bird_scaled,40,20,width,height);
  204.       fg_pack(bird_scaled,bird_packed,width,height);
  205.       fg_drwimage(bird_packed,width/2,height);
  206.       sprintf(string,"%2dx%2d",width,height);
  207.       center_pstring(string,x,x+width,270);
  208.    }
  209.  
  210.    /* wait for a keystroke */
  211.  
  212.    fg_mousevis(ON);
  213.    wait_for_keystroke();
  214.    fg_mousevis(OFF);
  215.  
  216.    /* restore the screen and return */
  217.  
  218.    fg_restore(0,xlimit,menu_bottom,ylimit);
  219.    fg_palettes(default_colors);
  220.    redraw = TRUE;
  221.    fg_mousevis(ON);
  222.    return(OK);
  223. }
  224.  
  225. /**********************************************************************\
  226. *                                                                      *
  227. *  do_scroll -- do a circular scroll of part of the screen             *
  228. *                                                                      *
  229. \**********************************************************************/
  230.  
  231. do_scroll()
  232. {
  233.    register int i;
  234.    int y1,y2;
  235.  
  236.    y1 = 4;
  237.    y2 = ylimit - y1;
  238.  
  239.    fg_mousevis(OFF);
  240.  
  241.    /* save the area under the scroll */
  242.  
  243.    fg_transfer(280,439,y1,y2,0,y2,hidden,hidden);
  244.  
  245.    /* do a nice circular scroll */
  246.  
  247.    for (i = y1; i <= y2; i+=2)
  248.       fg_scroll(280,439,y1,y2,-2,0);
  249.  
  250.    /* fix the area under the scroll */
  251.  
  252.    fg_transfer(0,159,y1,y2,280,y2,hidden,hidden);
  253.    fg_save(0,159,y1,y2);
  254.  
  255.    fg_mousevis(ON);
  256.    return(OK);
  257. }
  258.  
  259. /**********************************************************************\
  260. *                                                                      *
  261. *  do_split -- demo the split screen effect                            *
  262. *                                                                      *
  263. \**********************************************************************/
  264.  
  265. do_split()
  266. {
  267.    register int y;
  268.    int lower, upper;
  269.  
  270.    if (!exists("MOUNTAIN.PCX"))
  271.       abort_program("File missing: MOUNTAIN.PCX.\n");
  272.  
  273.    /* the lower area will be page 0, the upper area page 1 */
  274.  
  275.    lower = 0;
  276.    upper = 1;
  277.  
  278.    /* display the MOUNTAIN.PCX file on the hidden page (page 1) */
  279.  
  280.    fg_mousevis(OFF);
  281.    fg_setpage(hidden);
  282.    fg_showpcx("MOUNTAIN.PCX",0);
  283.  
  284.    /* activate a split screen environment with 100 lines at bottom */
  285.  
  286.    fg_split(ylimit-99);
  287.    fg_setvpage(upper);
  288.  
  289.    /* pan the MOUNTAIN.PCX image (in the upper area) up */
  290.  
  291.    for (y = 0; y < 100; y++)
  292.       fg_pan(0,y);
  293.    fg_waitfor(4);
  294.  
  295.    /* now pan it back to its original position */
  296.  
  297.    for (y = 99; y >= 0; y--)
  298.       fg_pan(0,y);
  299.  
  300.    /* wait for a keystroke */
  301.  
  302.    fg_mouselim(0,xlimit,0,ylimit-100);
  303.    fg_mousevis(ON);
  304.    wait_for_keystroke();
  305.    fg_mouselim(0,xlimit,0,ylimit);
  306.    fg_mousevis(OFF);
  307.  
  308.    /* disable the split screen environment */
  309.  
  310.    fg_setvpage(lower);
  311.    fg_split(ylimit+1);
  312.  
  313.    /* restore the original menu screen */
  314.  
  315.    fg_palettes(default_colors);
  316.    draw_screen(3);
  317.    redraw = TRUE;
  318.    return(OK);
  319. }
  320.  
  321. /**********************************************************************\
  322. *                                                                      *
  323. * do_transfer -- demo the transfer function                            *
  324. *                                                                      *
  325. \**********************************************************************/
  326.  
  327. do_transfer()
  328. {
  329.    register int i;
  330.    int x,y;
  331.    int ymin,ymax;
  332.  
  333.    static char *string[] = {
  334.    "Transfer",
  335.    "Use Fastgraph's image transfer routines",
  336.    "to copy rectangular areas, either on the",
  337.    "same video page or different video pages."
  338.     };
  339.  
  340.    /* clear work area of visual page and display the info window */
  341.  
  342.    fg_mousevis(OFF);
  343.    fg_restore(0,xlimit,menu_bottom,ylimit);
  344.    info_window(24,419,60,string,4);
  345.  
  346.    /* save the info window to the hidden page */
  347.  
  348.    ymin = 60;
  349.    ymax = ymin + 5 * (PTSIZE+1) + 2;
  350.    fg_save(24,419,ymin,ymax);
  351.  
  352.    /* transfer a 6 copies of the info window from hidden page to visual */
  353.  
  354.    x = 56;
  355.    y = ymax+PTSIZE+1;
  356.    for (i = 0; i < 6; i++)
  357.    {
  358.       fg_transfer(24,419,ymin,ymax,x,y,hidden,visual);
  359.       x += 32;
  360.       y += PTSIZE;
  361.       fg_waitfor(2);
  362.    }
  363.  
  364.    /* wait for a keystroke */
  365.  
  366.    fg_mousevis(ON);
  367.    wait_for_keystroke();
  368.  
  369.    fg_mousevis(OFF);
  370.  
  371.    /* clear the area where the info window was on the hidden page */
  372.  
  373.    y = 5 * (PTSIZE+1) + 2;
  374.  
  375.    fg_transfer(24,419,ymax+1,ymax+y+1,24,ymax,hidden,hidden);
  376.  
  377.    /* restore the screen and return */
  378.  
  379.    fg_restore(0,xlimit,menu_bottom,ylimit);
  380.    redraw = TRUE;
  381.  
  382.    fg_mousevis(ON);
  383.    return(OK);
  384. }
  385.